#include "../TimerWheel.hpp"

class TimerTest
{
private:
    int _data;

public:
    TimerTest(int data) : _data(data) { std::cout << "test 构造!\n"; }
    ~TimerTest() { std::cout << "test 析构!\n"; }
};
void del(TimerTest *t)
{
    delete t;
}
int main()
{
    TimerTaskQueue que;
    int id = 3;
    TimerTest *t = new TimerTest(10);
    que.TimerTaskAdd(std::bind(del, t), 5, id);
    for (int i = 0; i < 5; i++)
    {
        sleep(1);
        que.RefreshTimeTask(id);
        std::cout << "刷新了⼀下3号定时任务!\n";
        que.RunTimerWheel(); // 每秒调⽤⼀次，模拟定时器
    }
    std::cout << "刷新定时任务停⽌, 5s后释放任务将被执⾏\n";
    while (1)
    {
        std::cout << "--------------------\n";
        sleep(1);
        que.RunTimerWheel(); // 每秒调⽤⼀次，模拟定时器
        if (que.HasTask(id) == false)
        {
            std::cout << "定时任务已经被执⾏完毕！\n";
            break;
        }
    }
    return 0;
}